<template>
  <div class="my-coupon">
    <div class="coupon-image" v-if="url">
      <img :src="url" alt="" style="object-fit: scale-down;">
    </div>
  </div>
</template>

<script>
export default {
  props: {
    data: {
      type: Object,
      default: () => ({})
    }
  },
  computed: {
    url () {
      return this.data.url
    },
    type () { // custom 普通优惠券, 裂变优惠券?
      return this.data.type
    },
    width () {
      return Number(this.data.width) || 375
    },
    height () {
      return Number(this.data.height) || 0
    },
    radio () {
      return this.height / this.width
    }
  },
  mounted () {
    if (this.$el) {
      const el = this.$el
      el.style.setProperty('--height', 0)
      el.style.setProperty('--paddingBottom', `calc(${this.radio} * 100%)`)
    }
  }
}
</script>

<style lang="less" scoped>
.my-coupon {
  --height: 100px;
  --paddingBottom: 0;
  position: relative;
  width: 100%;
  height: var(--height);
  padding-bottom: var(--paddingBottom);
  box-sizing: border-box;
  overflow: hidden;
  .coupon-image {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
  }
}
</style>